﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DiscoveryLogic.Analytics.DataObjects.Networks;
using DiscoveryLogic.Analytics.UI.Common.Events;
using Microsoft.Practices.Composite.Events;
using Microsoft.Practices.Composite.Wpf.Events;

namespace DiscoveryLogic.Analytics.Modules.Networks
{
    public class NetworkStatsPresenter
    {
        private readonly IEventAggregator _EventAggregator;
        private SubscriptionToken _ViewStatsToken;

        private NetworkStats _View;
        /// <summary></summary>
        public NetworkStats View
        {
            get
            {
                return this._View;
            }
            set
            {
                this._View = value;
            }
        }


        public NetworkStatsPresenter(IEventAggregator eventAggregator)
        {
            this._EventAggregator = eventAggregator;
        }

        public void RegisterViewStatsEventHandler(Network network)
        {
            ViewNetworkStatsEvent viewNetworkStatsEvent =
                    _EventAggregator.GetEvent<ViewNetworkStatsEvent>();
            if (this._ViewStatsToken != null)
            {
                viewNetworkStatsEvent.Unsubscribe(_ViewStatsToken);
            }
            this._ViewStatsToken = viewNetworkStatsEvent.Subscribe(
                this._View.PopulateNetworkStats,
                ThreadOption.UIThread,
                false);
        }
    }
}
